# Maintainer: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
# Contributor: Hannes Graeuler <hgraeule @ uos dot de>

pkgname=pngquant
pkgver=3.0.3
pkgrel=2
pkgdesc="Command-line utility to quantize PNGs down to 8-bit paletted PNGs"
arch=('loong64' 'x86_64')
url="https://pngquant.org/"
license=('BSD')
depends=('libpng' 'lcms2')
makedepends=('cargo')
source=("https://github.com/kornelski/$pkgname/archive/$pkgver/$pkgname-$pkgver.tar.gz")
sha256sums=('ddd8889a9c269ba454d0c5e4f7167948d55d77c4570b23f671809fd3a68b6822')

prepare() {
    cd "$srcdir/$pkgname-$pkgver"
    sed -i 's|, path = "lib/imagequant-sys"||' Cargo.toml
    cargo fetch --target "`uname -m`-unknown-linux-gnu"
}

build() {
    cd "$srcdir/$pkgname-$pkgver"
    export RUSTUP_TOOLCHAIN=stable
    export CARGO_TARGET_DIR=target
    cargo build --release
}

check() {
    cd "$srcdir/$pkgname-$pkgver"
    export RUSTUP_TOOLCHAIN=stable
    cargo test
}

package() {
    cd "$srcdir/$pkgname-$pkgver"
    install -Dm755 target/release/pngquant "$pkgdir/usr/bin/pngquant"
    install -Dm644 pngquant.1 "$pkgdir/usr/share/man/man1/pngquant.1"
    install -Dm644 COPYRIGHT "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
